<template>
  <el-form ref="form" :rules="rules" :model="currentRoom" label-width="120px" class="demo-form">
    <el-form-item label="所属企业" prop="deptName">
      <el-input v-model="currentRoom.deptName" disabled></el-input>
    </el-form-item>
    <el-form-item label="中控室名称" prop="name">
      <el-input v-model="currentRoom.name"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="save('form')">保存</el-button>
      <el-button @click="back">返回</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  props: {
    isClose: Boolean
  },
  created() {},
  mounted() {},
  computed: {
    ...mapGetters({
      currentRoom: "currentRoom"
    })
  },
  data() {
    return {
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { min: 1, max: 15, message: "长度在 1 到 15 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    save(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$store
            .dispatch("addOrUpdateControlRoomS", this.currentRoom)
            .then(ret => {
              this.$notify({
                title: "添加成功",
                type: "success"
              });
              this.back();
            });
        } else {
          return false;
        }
      });
    },
    back() {
      this.$emit("close");
    }
  },
  components: {}
};
</script>
<style>
</style>
